layui.use(['table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;

    /**
     * 吃在玩在建湖表管理
     */
    var JhTravelInfo = {
        tableId: "jhTravelInfoTable"
    };

    /**
     * 初始化表格的列
     */
    JhTravelInfo.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', align: 'center', hide: true, title: '主键id'},
            {field: 'name', align: 'center', sort: true, title: '地点名称'},
            // {field: 'coverPhoto', align: 'center', sort: true, title: '封面图片'},
            //{field: 'topImgUrl', align: 'center', sort: true, title: '顶部图片'},
            {field: 'beginTime', align: 'center', sort: true, title: '开始营业时间'},
            {field: 'endTime', align: 'center', sort: true, title: '结束营业时间'},
            {field: 'phone', align: 'center', sort: true, title: '联系电话'},
            {field: 'address', align: 'center', sort: true, title: '具体地址'},
            //{field: 'homePageIntroduction', align: 'center', sort: true, title: '首页介绍'},
            //{field: 'introduction', align: 'center', sort: true, title: '具体介绍'},
            {field: 'type', align: 'center', sort: true, title: '分类'},
            {field: 'consume', align: 'center', sort: true, title: '浏览量计算'},
            {align: 'center', toolbar: '#tableBar', title: '操作'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    JhTravelInfo.search = function () {
        var queryData = {};
        queryData['name'] = $("#name").val();
        queryData['type'] = $("#type").val();
        table.reload(JhTravelInfo.tableId, {
            where: queryData, page: {curr: 1}
        });
    };

    /**
     * 弹出添加对话框
     */
    JhTravelInfo.openAddDlg = function () {
        func.open({
            title: '添加吃在玩在建湖表',
            maxmin: true,
            content: Feng.ctxPath + '/jhTravelInfo/add',
            tableId: JhTravelInfo.tableId,
            maxmin: true
        });
    };

    /**
     * 点击编辑
     *
     * @param data 点击按钮时候的行数据
     */
    JhTravelInfo.openEditDlg = function (data) {
        func.open({
            title: '修改吃在玩在建湖表',
            maxmin: true,
            content: Feng.ctxPath + '/jhTravelInfo/edit?id=' + data.id,
            tableId: JhTravelInfo.tableId,
            maxmin: true
        });
    };

    /**
     * 导出excel按钮
     */
    JhTravelInfo.exportExcel = function () {
        var checkRows = table.checkStatus(JhTravelInfo.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    /**
     * 点击删除
     *
     * @param data 点击按钮时候的行数据
     */
    JhTravelInfo.onDeleteItem = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/jhTravelInfo/delete", function (data) {
                Feng.success("删除成功!");
                table.reload(JhTravelInfo.tableId);
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", data.id);
            ajax.start();
        };
        Feng.confirm("是否删除?", operation);
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + JhTravelInfo.tableId,
        url: Feng.ctxPath + '/jhTravelInfo/list',
        page: true,
        height: "full-158",
        cellMinWidth: 100,
        cols: JhTravelInfo.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        JhTravelInfo.search();
    });

    // 添加按钮点击事件
    $('#btnAdd').click(function () {
        JhTravelInfo.openAddDlg();
    });

    // 导出excel
    $('#btnExp').click(function () {
        JhTravelInfo.exportExcel();
    });

    // 工具条点击事件
    table.on('tool(' + JhTravelInfo.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            JhTravelInfo.openEditDlg(data);
        } else if (layEvent === 'delete') {
            JhTravelInfo.onDeleteItem(data);
        }
    });
});
